package models

import (
	"gorm.io/gorm"
	"zk/zg3_zk2/src/pro/global"
)

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);unique;comment:'手机号'"`
	Password string `gorm:"type:char(32);comment:'密码'"`
}

func (u *User) GetUserByMobile(mobile string) error {
	return global.DB.Where("mobile=?", mobile).Limit(1).Find(&u).Error
}

func (u *User) Register() error {
	return global.DB.Create(&u).Error
}

// 用户主页信息
type UserInfo struct {
	UserId   int64  //用户ID
	NickName string //昵称
	account  string //ID
	Fans     int    //粉丝数量
	Follow   int    //关注数量
}

func (ui *UserInfo) GetUserInfByUserId(userId int) error {
	return global.DB.Where("user_id=?", userId).Limit(1).Find(&ui).Error
}
